package com.ruoyi.project.ypgl.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.ypgl.domain.YpglGys;
import com.ruoyi.project.ypgl.domain.YpglSccj;
import com.ruoyi.project.ypgl.service.IYpglGysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ypgl/gys")
public class YpglGysController extends BaseController {


    @Autowired
    private IYpglGysService ypglGysService;

    @PreAuthorize("@ss.hasPermi('ypgl:gys:list')")
    @GetMapping("/list")
    public TableDataInfo list(YpglGys gys){
        startPage();
        List<YpglGys> list = ypglGysService.selectGysList(gys);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('ypgl:gys:add')")
    @Log(title = "管理供应商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody YpglGys gys)
    {

        gys.setCreateBy(SecurityUtils.getUsername());
        return toAjax(ypglGysService.insertGys(gys));
    }



    @PreAuthorize("@ss.hasPermi('ypgl:gys:query')")
    @GetMapping(value = "/{gysId}")
    public AjaxResult getInfo(@PathVariable Long gysId)
    {
        return AjaxResult.success(ypglGysService.selectGysById(gysId));
    }


    @PreAuthorize("@ss.hasPermi('ypgl:gys:edit')")
    @Log(title = "管理供应商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody YpglGys gys)
    {

        gys.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(ypglGysService.updateGys(gys));
    }


    @PreAuthorize("@ss.hasPermi('ypgl:gys:remove')")
    @Log(title = "管理供应商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{gysIds}")
    public AjaxResult remove(@PathVariable Long[] gysIds)
    {
        return toAjax(ypglGysService.deleteGysByIds(gysIds));
    }



}
